<template>

	<view>
		<bg-video></bg-video>
		<cu-custom bgColor="bg-main" :isBack="true">
			<block class="text-white" slot="content">会员购买</block>
		</cu-custom>
		<view>
			<view class="cu-item shadow">
				<view class="cu-list menu-avatar">
					<view class="cu-item">
						<!-- <view class="cu-avatar round lg" :style="'background-image:url('+ajiaolian.cover+');'"> -->
						<view class="cu-avatar round lg" :style="'background-image:url('+ajiaolian.cover+');'">
						</view>
						<view class="content flex-sub">
							<view class="flex justify-between">
								<text>{{ajiaolian.jlname ? ajiaolian.jlname : "未设置昵称"}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>


			<view class="margin-sm shadow bg-white padding-xs">
				<view class="padding-xs flex justify-between">
					<text>{{hylx.hlname}}</text>
					<text>￥{{hylx.amount / 100}}</text>
				</view>
				<view class="padding-xs flex justify-between">
					<text>{{hylx.cs}}次</text>
					<text>{{hylx.zq}}天有效</text>
				</view>
			</view>
		</view>

		<view class="padding">
			<button @click="toBuy" class="cu-btn block bg-main lg">购买</button>
		</view>
	</view>
</template>

<script>
	export default {
		data: function() {
			return {
				hylx: {},
				ajiaolian: {},
				ahyjl: {
					hyjlid: "",
					hylxid: "",
					clientid:this.store.state.client.clientid,
					amount: 0,
					jlid: "",
					cd: 0,
					sd: "",
					ed: "",
					zq: "",
					prepayid: "",
					prepaydata: "",
					pflg: "",
					tkflg: "",
					stu: "",
					cs: "",
					sycs: ""
				},
				

			};
		},
		onShareAppMessage: function(){
			return {
				title: this.store.state.title,
				path: '/pages/first?id='+this.store.state.client.clientid
			}
		},
		onLoad: function(option) {
			this.hylx.hylxid = option.hylxid;
			this.getHylx();
		},
		methods: {
			//获取会员类型
			getHylx: function() {
				this.api("/jl/hylx/get").send({
					hylxid: this.hylx.hylxid,
				}).then(res => {
					this.hylx = res.hylx;
					this.ajiaolian = res.ajiaolian;
				});
			},


			//购买，生成会员记录
			toBuy: function() {
				if (this.hylx.jlid == this.store.state.jl.jlid) {
					this.message.info("不能购买自己的会员");
					return;
				}
				this.api("/client/hy/info").send({
					hylxid: this.hylx.hylxid,
					clientid: this.store.state.client.clientid,
					jlid: this.hylx.jlid
				}).then(data => {
					let ahyjl = data.ahyjl;
					this.pay.exePay(JSON.parse(ahyjl.prepaydata)).then(res => {
						this.http.post({
							url: `/client/hyjl/payHyAfter/${ahyjl.hyjlid}`,
						}).then(() => {
							this.message.info("购买会员成功");
						});
					}).catch(payError => {
						console.error('支付失败:', payError);
						this.message.info("支付失败");
					});
					//uni.navigateBack();
				});
			},
		}
	}
</script>

<style>
</style>